package com.han.cloud.service.impl;

import com.han.cloud.dao.PaymentDao;
import com.han.cloud.dto.TradeDTO;
import com.han.cloud.entity.TradeDO;
import com.han.cloud.service.PaymentService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author hanky
 * @date 2021/10/17
 */
@Service
public class PaymentServiceImpl implements PaymentService {

    @Resource
    private PaymentDao paymentDao;

    @Override
    public String saveTrade(TradeDTO tradeDTO) {
        TradeDO tradeDO = new TradeDO();
        BeanUtils.copyProperties(tradeDTO, tradeDO);
        paymentDao.insert(tradeDO);
        return tradeDO.getId();
    }

    @Override
    public TradeDTO getTrade(String id) {
        TradeDO tradeDO = paymentDao.selectById(id);
        TradeDTO tradeDTO = new TradeDTO();
        if (tradeDO != null)
            BeanUtils.copyProperties(tradeDO, tradeDTO);
        return tradeDTO;
    }
}
